package com.bootdo.staticmask.controller;

import java.util.List;
import java.util.Map;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.bootdo.staticmask.domain.MaskMethodDO;
import com.bootdo.staticmask.service.MaskMethodService;
import com.bootdo.common.utils.PageUtils;
import com.bootdo.common.utils.Query;
import com.bootdo.common.utils.R;

/**
 * 脱敏方法
 * 
 * @author lkg
 * @email lkggod@163.com
 * @date 2018-04-25 11:27:35
 */
 
//@Controller
//@RequestMapping("/staticmask/maskMethod")
public class MaskMethodController {

	private final MaskMethodService maskMethodService;

	@Autowired
	public MaskMethodController(MaskMethodService maskMethodService) {
		this.maskMethodService = maskMethodService;
	}


	@GetMapping()
//	@RequiresPermissions("staticmask:maskMethod:maskMethod")
	String MaskMethod(){
	    return "staticmask/maskMethod/maskMethod";
	}

	@ResponseBody
	@GetMapping("/findAll")
	public List<MaskMethodDO> findAll(){
		return maskMethodService.findAll();
	}


	@ResponseBody
	@GetMapping("/list")
//	@RequiresPermissions("staticmask:maskMethod:maskMethod")
	public PageUtils list(@RequestParam Map<String, Object> params){
		//查询列表数据
        Query query = new Query(params);
		List<MaskMethodDO> maskMethodList = maskMethodService.list(query);
		int total = maskMethodService.count(query);
		PageUtils pageUtils = new PageUtils(maskMethodList, total);
		return pageUtils;
	}
	
	@GetMapping("/add")
	@RequiresPermissions("staticmask:maskMethod:add")
	String add(){
	    return "staticmask/maskMethod/add";
	}

	@GetMapping("/edit/{maskMethodId}")
	@RequiresPermissions("staticmask:maskMethod:edit")
	String edit(@PathVariable("maskMethodId") Integer maskMethodId,Model model){
		MaskMethodDO maskMethod = maskMethodService.get(maskMethodId);
		model.addAttribute("maskMethod", maskMethod);
	    return "staticmask/maskMethod/edit";
	}
	
	/**
	 * 保存
	 */
	@ResponseBody
	@PostMapping("/save")
	@RequiresPermissions("staticmask:maskMethod:add")
	public R save( MaskMethodDO maskMethod){
		if(maskMethodService.save(maskMethod)>0){
			return R.ok();
		}
		return R.error();
	}
	/**
	 * 修改
	 */
	@ResponseBody
	@RequestMapping("/update")
	@RequiresPermissions("staticmask:maskMethod:edit")
	public R update( MaskMethodDO maskMethod){
		maskMethodService.update(maskMethod);
		return R.ok();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/remove")
	@ResponseBody
	@RequiresPermissions("staticmask:maskMethod:remove")
	public R remove( Integer maskMethodId){
		if(maskMethodService.remove(maskMethodId)>0){
		return R.ok();
		}
		return R.error();
	}
	
	/**
	 * 删除
	 */
	@PostMapping( "/batchRemove")
	@ResponseBody
	@RequiresPermissions("staticmask:maskMethod:remove")
	public R remove(@RequestParam("ids[]") Integer[] maskMethodIds){
		maskMethodService.batchRemove(maskMethodIds);
		return R.ok();
	}
	
}
